import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/order/order-return-apply';


export interface OrderReturnApplyParam {
    orderId?: string;
    orderNo?: string;
    username?: string;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface OrderReturnApplyResponse {
    id?: number;
    orderId: string;
    orderItemId: string;
    orderNo?: string;
    skuId?: string;
    username?: string;
    freight?: string;
    returnCount?: string;
    returnReason?: string;
    returnComment?: string;
    returnPic?: string;
    returnApplyStatus?: number;
    returnLogisticCode?: string;
    returnReceiveName?: string;
    returnReceiveNote?: string;
    returnReceivePhone?: string;
    returnCompanyAddress?: string;
    returnReceiveTime?: string;
    handleNote?: string;
    handleBy?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface OrderReturnApplySaveCommand {
    id?: number;
    orderId: string;
    orderItemId: string;
    orderNo?: string;
    skuId?: string;
    username?: string;
    freight?: string;
    returnCount?: string;
    returnReason?: string;
    returnComment?: string;
    returnPic?: string;
    returnApplyStatus?: number;
    returnLogisticCode?: string;
    returnReceiveName?: string;
    returnReceiveNote?: string;
    returnReceivePhone?: string;
    returnCompanyAddress?: string;
    returnReceiveTime?: string;
    handleNote?: string;
    handleBy?: string;
}

export interface OrderReturnApplyResponseList {
    list: OrderReturnApplyResponse[];
    total: number;
}


// 通过OrderReturnApplyParam参数获取分页列表
export function pageOrderReturnApply(params: OrderReturnApplyParam) {
    return axios.get<OrderReturnApplyResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取订单退货申请信息
export function getOrderReturnApply(id: number) {
    return axios.get<OrderReturnApplyResponse>(`${BASE_URL}/${id}`);
    
}

export function listOrderReturnApply(params: OrderReturnApplyParam) {
    return axios.get<OrderReturnApplyResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加订单退货申请
export function addOrderReturnApply(params: OrderReturnApplySaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新订单退货申请
export function updateOrderReturnApply(params: OrderReturnApplySaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除订单退货申请
export function deleteOrderReturnApply(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}